﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using com.woodsoft.core;
using com.woodsoft.core.Files;
using EQ1.Objects;

namespace EQ1.Elements {
  public class Screens : UIElement , IUIElement<Screens> {
    public Screens ( UIDocument doc , string name )
      : base("", name, "",  doc ) {
    }
    public Screens ( UIDocument doc )
      : this( doc , "Screens" ) {
    }

    #region IUIElement<Screens> Members

    public void Validate ( Screens val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        Screens el = new Screens( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }

    public void Copy ( Screens val ) {
      if( !string.IsNullOrEmpty( val.ScreenName ) )
        this.ScreenName = val.ScreenName;
      if( val.InitialSettings != null )
        this.InitialSettings = val.InitialSettings;

    }

    #endregion

    public string ScreenName {
      get {
        return this.GetElement( "ScreenName" ).InnerText;
      }
      set {
        this.Validate( "ScreenName" , value );
      }
    }
    public XmlNodeList InitialSettings {
      get {
        return this.GetElementsByTagName( "InitialSettings" );
      }
      set {
        foreach( XmlNode nd in value ) {
          if( nd.LocalName == "InitialSettings" )
            this.AddSetting( nd.InnerText );
        }
      }
    }
    public void AddSetting ( string val ) {
      if( !string.IsNullOrEmpty( val ) ) {
        for( int i = this.InitialSettings.Count - 1 ; i >= 0 ; i-- ) {
          if( this.InitialSettings[i].InnerText == val )
            return;
        }

        this.AddElement( "InitialSettings" , val );
      }
    }
  }
}
